#!/bin/bash

APP=ycreal
HIVE_APP=waterflow

starttime=`date +'%Y-%m-%d %H:%M:%S'`


if [ -n "$2" ] ;then
    string=$2
else
    string=`date +'%Y-%m-%d %H:%M:%S'`
fi 
 
 
array=(`echo $string | tr ' ' ' '` )  

flag=0 
 
for var in ${array[@]}
do
    if [ ${flag} -eq 0 ]; then
		day=$var
	fi
   time=$var
   flag=1
done 


string=$time 
array=(`echo $string | tr ':' ' '` )


hour=${time:0:2}
min=${time:3:2}

echo $day
echo $hour
echo "old" $min

thisString="01 02 03 04 05 06 07 08 09 10 11 12 13 14" # 源字符串
searchString=${min} # 搜索字符串
case $thisString in
	*"$searchString"*) echo "包含(01~15)" 
	min='00'
	;;
	*) echo "不包含(01~15)" 
	;;
esac

thisString="16 17 18 19 20 21 22 23 24 25 26 27 28 29" # 源字符串
searchString=${min} # 搜索字符串
case $thisString in
	*"$searchString"*) echo "包含(16~30)" 
	min='15'
	;;
	*) echo "不包含(16~30)" 
	;;
esac

thisString="31 32 33 34 35 36 37 38 39 40 41 42 43 44" # 源字符串
searchString=${min} # 搜索字符串
case $thisString in
	*"$searchString"*) echo "包含(31~45)" 
	min='30'
	;;
	*) echo "不包含(31~45)" 
	;;
esac

thisString="46 47 48 49 50 51 52 53 54 55 56 57 58 59" # 源字符串
searchString=${min} # 搜索字符串
case $thisString in
	*"$searchString"*) echo "包含(46~59)" 
	min='45'
	;;
	*) echo "不包含(46~59)" 
	;;
esac

echo $day
echo $hour
echo "new" $min

# 在处理完时间的基础上，进行时间操作

ods_waterflow="
load data inpath '/origin_water_data/$APP/db/st_pptn_r/$day/$hour/$min' OVERWRITE into table ${HIVE_APP}.ods_waterflow partition(day='$day', hour='$hour', min='$min');"


ods_base_region=" 
load data inpath '/origin_water_data/$APP/db/st_grid_point/$day/$hour/$min' OVERWRITE into table ${HIVE_APP}.ods_base_region;"

ods_site_info="
load data inpath '/origin_water_data/$APP/db/st_stbprp_b/$day/$hour/$min' OVERWRITE into table ${HIVE_APP}.ods_site_info;"

case $1 in
    "ods_base_region"){
        hive -e "$ods_base_region"
    };;
    "ods_site_info"){
        hive -e "$ods_site_info"
    };;
    "ods_waterflow"){
        hive -e "$ods_waterflow"
    };;
    "all"){
        hive -e "$ods_base_region$ods_site_info$ods_waterflow"
		#hive -e "$ods_waterflow"
    };;
esac

endtime=`date +'%Y-%m-%d %H:%M:%S'`
start_seconds=$(date --date="$starttime" +%s);
end_seconds=$(date --date="$endtime" +%s);
echo "本次运行时间: "$((end_seconds-start_seconds))"s"


